package com.luobo.todolist.controller;

import com.luobo.todolist.entity.Result;
import com.luobo.todolist.entity.Todo;
import com.luobo.todolist.service.TodoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Todo控制层
 */
@RestController
@RequestMapping("/api/todo")
public class TodoController {

    @Autowired
    private TodoService todoService;

    /**
     * 添加待办事项
     */
    @PostMapping
    public Result<Boolean> add(@RequestBody Todo todo) {
        return Result.success(todoService.add(todo));
    }

    /**
     * 删除待办事项
     */
    @DeleteMapping("/{id}")
    public Result<Boolean> delete(@PathVariable Long id) {
        return Result.success(todoService.delete(id));
    }

    /**
     * 更新待办事项
     */
    @PutMapping
    public Result<Boolean> update(@RequestBody Todo todo) {
        return Result.success(todoService.update(todo));
    }

    /**
     * 更新待办事项状态
     */
    @PutMapping("/{id}/status/{status}")
    public Result<Boolean> updateStatus(@PathVariable Long id, @PathVariable Integer status) {
        return Result.success(todoService.updateStatus(id, status));
    }

    /**
     * 根据ID查询待办事项
     */
    @GetMapping("/{id}")
    public Result<Todo> getById(@PathVariable Long id) {
        return Result.success(todoService.getById(id));
    }

    /**
     * 查询所有待办事项
     */
    @GetMapping("/list")
    public Result<List<Todo>> list() {
        return Result.success(todoService.listAll());
    }

    /**
     * 按状态查询待办事项
     */
    @GetMapping("/list/{status}")
    public Result<List<Todo>> listByStatus(@PathVariable Integer status) {
        return Result.success(todoService.listByStatus(status));
    }
} 